﻿using HDS.Admin.Api.ViewModels.Commission;
using HDS.IService.Master;
using HDS.Model;
using HDS.Model.Entity.Master;
using HDS.Model.Entity.View;
using LinqKit;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Security.Claims;
using System.Threading.Tasks;

namespace HDS.Admin.Api.Controllers
{
    [Route("[controller]/[action]")]
    [ApiController]
    [EnableCors]
    public class CommissionController : AdminController
    {
        private readonly ILogger<CommissionController> _logger;
        private readonly ICommissionService _ICommissionService;
        private readonly ISupplierApiConfigService _ISupplierApiConfigService;
        private readonly IDistributorService _IDistributorConfigService;

        public CommissionController(ILogger<CommissionController> logger, ICommissionService icommissionService, ISupplierApiConfigService isupplierApiConfigService, IDistributorService idistributorConfigService)
        {
            _logger = logger;
            _ICommissionService = icommissionService;
            _ISupplierApiConfigService = isupplierApiConfigService;
            _IDistributorConfigService = idistributorConfigService;
        }

        public async Task<ResultData<DataPagingModel<VHotelCommission>>> GetList([FromBody] SearchDto searchDto)
        {
            var dataPaging = await _ICommissionService.GetList(searchDto.PageIndex, searchDto.PageSize, searchDto.Distributor, searchDto.Supplier, searchDto.CountryCode, searchDto.CityCode, searchDto.HotelId, searchDto.Type);

            return new ResultData<DataPagingModel<VHotelCommission>> { Success = true, Data = dataPaging };
        }

        public async Task<ResultData<string>> Update([FromBody] HotelCommission entity)
        {
            entity.UpdatedBy = this.UserId;
            entity.UpdatedByName = this.UserName;
            entity.UpdatedTime = DateTime.Now;
            await _ICommissionService.Update(entity);
            return new ResultData<string> { Success = true };
        }

        public async Task<ResultData<string>> Delete(int Id)
        {
            await _ICommissionService.Delete(Id);
            return new ResultData<string> { Success = true };
        }
    }
}
